package com.itheima01;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) throws IOException {
//        String path1="C:\\Users\\阳光正直夏明伟15805655221\\Desktop\\考试\\素材01.txt";
        String path1 = "Test\\dir\\managers.txt";
        String path2 = "Test\\dir\\subways.txt";

        BufferedReader br = new BufferedReader(new FileReader(path1));

        ArrayList<Manger> arr = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            String[] split = line.split(",");
            Manger manger = new Manger();
            manger.setWorkId(Integer.parseInt(split[0]));
            manger.setName(split[1]);
            manger.setGander(split[2]);
            manger.setPhoneNum(split[3]);
            arr.add(manger);
        }
        br.close();
//        arr.forEach(s-> System.out.println(s));

        BufferedReader br1 = new BufferedReader(new FileReader(path2));
        ArrayList<Subway> arr1 = new ArrayList<>();
        String line1;
        while ((line1 = br1.readLine()) != null) {
            String[] split = line1.split(",");
            Subway subway = new Subway();
            subway.setSubwayId(split[0]);
            subway.setSubwayName(split[1]);
            subway.setWay(split[2]);
            arr1.add(subway);
        }
        br1.close();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入管理工号:");
        String num = sc.nextLine();
        System.out.println("请输入管理姓名:");
        String name = sc.nextLine();
        int count = -1;
        for (Manger manger : arr) {
            String workId = manger.getWorkId() + "";
            String name1 = manger.getName();

            if (workId.equals(num)) {
                if (name1.equals(name)) {
                    System.out.println("登录成功");

                    count++;
                    break;
                }
            }
        }
        if (count == -1) {
            System.out.println("登录失败");
        }
    }

}

